﻿using System.Web.Mvc;
using EPiServer.Shell;

namespace OpenWaves.EPiServer.BrightcoveVideoCloudProperty
{
    public class BrowserController : Controller
    {
        public JsonResult GetVideos(string phrase = "", int pageNumber = 0, int itemsPerPage = 12)
        {
            var service = new VideoCloudService();
            var builder = new QueryBuilder();

            return Json(service.GetVideos(builder.SearchFor(phrase).GetPage(pageNumber).Take(itemsPerPage).ToQuery()), JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetVideo(long videoId)
        {
            var service = new VideoCloudService();
            return Json(service.GetVideo(videoId), JsonRequestBehavior.AllowGet);
        }

        public static string GetControllerPath()
        {
            return Paths.ToResource(typeof (BrowserController), "browser");
        }       
    }
}